<section id="main-content">
	<section class="wrapper">
		<!--state overview end-->
		<div class="row">
			<div class="col-lg-12">
				<!-- <div class="view-header">
          <div class="view-search">
            <label class="pull-left">菜单：</label>
            <select id="level1" class="form-control" onchange="change(this.value)">
              <option value="">全部</option>
              <option value="XXZX">信息中心</option>
              <option value="YYGL">运营管理</option>
              <option value="CGLC">物资管理</option>
              <option value="XZZX">行政中心</option>
              <option value="XTXX">系统管理</option>
              <option value="WDLC">我的流程</option>
              <option value="QT">其他</option>
            </select>

            <label class="pull-left">功能：</label>
            <select id="level2" class="form-control">
            </select>

            <label class="pull-left">人员：</label>
            <input type="text" value="" id="autocomplete" class="form-control" />
            <input type="hidden" value="" id="userId" />

            <button class="btn btn-info psearch" onclick="search(2);">搜索</button>
          </div>
        </div> -->

				<section class="panel">
					<div class="panel-body" style="padding-bottom:0;">
						<div class="row">
							<div class="col-lg-2">
								<div class="input-group m-bot15">
									<span class="input-group-addon" style="position: relative;z-index: 2;">菜单</span>
									<select class="form-control" style="position: relative;margin-left:-4px;text-indent:2px;" id="level1"
										onchange="change(this.value)">
										<option value="">全部</option>
										<option value="XXZX">信息中心</option>
										<option value="YYGL">运营管理</option>
										<option value="CGLC">物资管理</option>
										<option value="XZZX">行政中心</option>
										<option value="XTXX">系统管理</option>
										<option value="WDLC">我的流程</option>
										<option value="WDXM">我的项目</option>
									</select>
								</div>
							</div>
							<div class="col-lg-2">
								<div class="input-group m-bot15">
									<span class="input-group-addon" style="position: relative;z-index: 2;">功能</span>
									<select class="form-control" style="position: relative;margin-left:-4px;text-indent:2px;" id="level2">
									</select>
								</div>
							</div>
							<div class="col-lg-2">
								<div class="input-group m-bot15">
									<span class="input-group-addon">人员</span>
									<input type="text" id="autocomplete" value="" class="form-control"
										style="border-top-right-radius:4px;border-bottom-right-radius:4px;">
									<input type="hidden" value="" name="userId" id="userId" />
								</div>
							</div>
							<div class="col-lg-3">
								<button class="btn btn-info pull-left psearch" onclick="search(2);"
									style="margin-bottom:15px;">搜索</button>
							</div>
						</div>
					</div>
				</section>

				<section class="panel">
					<header class="panel-heading">
						权限信息
						<i class="button-next icon-plus" onclick="location.href='#/addRole'"> 新增</i>
					</header>
					<div class="panel-body">
						<div id="roleContainer" class="dlshouwen-grid-container"></div>
						<div id="roleToolBarContainer" class="dlshouwen-grid-toolbar-container"></div>
					</div>
					<div>
					</div>
				</section>
			</div>
		</div>
	</section>
</section>
<script type="text/javascript" src="js/autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript">
	function change(menu) {
		var selectid = document.getElementById("level2");
		$(selectid).empty();
		selectid.options.add(new Option("全部", ""));
		if (menu == "YYGL") {
			selectid.options.add(new Option("项目查询", "XMCX"));
			selectid.options.add(new Option("项目进展", "XMJZ"));
			selectid.options.add(new Option("客户列表", "KHLB"));
			selectid.options.add(new Option("合同管理", "HTGL"));
            selectid.options.add(new Option("工时报表", "GSBB"));
		} else if (menu == "CGLC") {
			selectid.options.add(new Option("资产管理", "XMZCGL"));
			selectid.options.add(new Option("物资管理", "WZGL"));
            selectid.options.add(new Option("资产历史", "ZCLS"));
		} else if (menu == "XZZX") {
			selectid.options.add(new Option("员工列表", "YGLB"));
			selectid.options.add(new Option("入职管理", "XYGRZ"));
			selectid.options.add(new Option("离职管理", "LZGL"));
			selectid.options.add(new Option("座位管理", "ZWGL"));
            selectid.options.add(new Option("员工归集", "YRCB"));
            selectid.options.add(new Option("成本设置", "CBSZ"));
            selectid.options.add(new Option("归集结果", "GJJG"));
		} else if (menu == "XXZX") {
			selectid.options.add(new Option("人员查询", "RYCZQX"));
		} else if (menu == "XTXX") {
			selectid.options.add(new Option("权限管理", "QXGL"));
		} else if (menu == "WDLC") {
			selectid.options.add(new Option("公章使用", "GZSY"));
		}else if (menu == "WDXM") {
            selectid.options.add(new Option("立项申请", "LXSQ"));
        }
	};
	change("");
	function roleList(CertusFormAjax) {
		//归属人
		CertusFormAjax.ajax("findSpUserList2", {}, function (response) {
			var html1 = '<input type="text" value="" id="autocomplete" class="form-control"/>' +
				'<input type="hidden" value="" id="searchParam"/>';
			$("#paramt").html(html1);
			var nhlTeams = [];
			var data = response.data;
			for (var i = 0; i < data.length; i++) {
				var arr = {};
				arr.name = data[i].userName + "[" + data[i].positonName + "]";
				arr.id = data[i].userId;
				nhlTeams.push(arr);
			}
			//自动补全
			var nhl = $.map(nhlTeams, function (obj) {
				return {
					value: obj.name,
					data: {
						category: obj.id
					}
				};
			});
			// Initialize autocomplete with local lookup:
			$('#autocomplete').devbridgeAutocomplete({
				lookup: nhl,
				minChars: 1,
				onSelect: function (suggestion) {
					$("#userId").val(suggestion.data.category);
				},
				showNoSuggestionNotice: true,
				noSuggestionNotice: 'Sorry, no matching results'
			});
		});

		var roleColumns = [{
			id: 'LEVEL1',
			title: '菜单',
			type: 'string',
			columnClass: 'text-center'
		}, {
			id: 'authorityName',
			title: '功能',
			type: 'string',
			columnClass: 'text-center',
		}
			//     {
			//     id: 'type',
			//     title: '类型',
			//     type: 'string',
			//     columnClass: 'text-center'
			// }, {
			//     id: 'authorityCode',
			//     title: '权限编码',
			//     type: 'string',
			//     columnClass: 'text-center'
			// }
			, {
			id: 'person',
			title: '所属人',
			type: 'string',
			columnClass: 'text-center',
			resolution: function (value, record) {
				var content = record.userName + "(" + record.userId + ")";
				return content;
			}
		},
		{
			id: 'viewCompany',
			title: '公司',
			type: 'string',
			columnClass: 'text-center',
			resolution: function (value) {
				var content = "";
				var arr = value.split(",");
				for (var i = 0; i < arr.length; i++) {
					if (arr[i] == "STSJT") {
						content += ",赛特斯集团";
					} else if (arr[i] == "STSNJ") {
						content += ",赛特斯南京";
					} else if (arr[i] == "HFXX") {
						content += ",浩方信息";
					} else if (arr[i] == "HFKJ") {
						content += ",浩方科技";
					} else if (arr[i] == "STSBJ") {
						content += ",赛特斯北京";
					} else if (arr[i] == "STSGD") {
						content += ",赛特斯广东";
					} else if (arr[i] == "STSSH") {
						content += ",赛特斯上海";
					} else if (arr[i] == "SYB-RX") {
						content += ",融合运维事业部";
					}else if (arr[i] == "HFXXBJ") {
                        content = "浩方信息北京";
                    }else if (arr[i] == "HFXXNJ") {
                        content = "浩方信息南京";
                    }else if (arr[i] == "HFXXSH") {
                        content = "浩方信息上海";
                    }
				}
				if (content != "") {
					content = content.substring(1, content.length);
				}
				return content;
			}
		},
		{
			id: 'createTime',
			title: '创建时间',
			type: 'date',
			format: 'yyyy-MM-dd',
			otype: 'time_stamp_ms',
			columnClass: 'text-center'
		}, {
			id: 'comments',
			title: '说明',
			type: 'string',
			columnClass: 'text-center',
		}, {
			id: 'operation',
			title: '操作',
			width: 130,
			type: 'string',
			columnClass: 'text-center',
			resolution: function (value, record) {
				var content = '';
				content += '<button class="btn btn-xs btn-success" onclick="edit(\'' + record.authorityCode + '\',\'' + record.userId + '\');"><i class="icon-exchange"></i>  编辑</button>';
				content += '&nbsp;&nbsp;';
				content += '<button class="btn btn-xs btn-danger" onclick="del(\'' + record.authorityCode + '\',\'' + record.userId + '\');"><i class="fa fa-trash-o"></i>  删除</button>';
				return content;
			}
		}];
		this.search = function (flag) {
			var userId = $("#userId").val();
			var level1 = $("#level1").val();
			var level2 = $("#level2").val();
			$("#roleContainer").empty();
			$("#roleToolBarContainer").empty();
			if (flag == 1) {
				level1 = "";
			}

			CertusFormAjax.ajax('findRoleList', { "userId": userId, "level1": level1, "level2": level2 }, function (result) {
				var telOption = {
					lang: 'zh-cn',
					ajaxLoad: false,
					extraWidth: 20,
					// loadURL:'url',
					exportFileName: '权限列表',
					datas: result.data,
					columns: roleColumns,
					gridContainer: 'roleContainer',
					toolbarContainer: 'roleToolBarContainer',
					tools: '',
					pageSize: 10,
					pageSizeLimit: [10, 15, 20]
				};
				var telGrid = $.fn.dlshouwen.grid.init(telOption);
				telGrid.load();
			});
		};

		search(1);
		//删除
		this.del = function (authorityCode, userId) {
			layer.confirm('确认删除此数据？', {
				btn: ['确定', '取消'] //按钮
			}, function () {
				CertusFormAjax.ajax('delRole', { "authorityCode": authorityCode, "userId": userId }, function () {
					window.location.reload();
					layer.msg("删除成功！");
				});
			});
		};
		// 跳转编辑
		this.edit = function (authorityCode, userId) {
			location.href = "#/toEditRole/" + authorityCode + "*" + userId;
		}
	}
</script>